var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(d, c, b) {
    if (status == 0 && d == 0) {
        cm.dispose();
        return
    }(d == 1) ? status++ : status--;
    selectionLog[status] = b;
    var a = -1;
    if (status <= a++) {
        cm.dispose()
    } else {
        if (status === a++) {
            cm.askMenu("欢呼与叹息交错的鸿运转盘箱！\r\n\r\n#b#L1#旋转吧！鸿运转盘箱！#k#l\r\n\r\n#L0##e<旋转吧！鸿运转盘箱！>#n 听取说明#l\r\n#L2#结束对话#l", 4, 9400966)
        } else {
            if (selectionLog[1] == 1) {
                action0(d, c, b, a)
            } else {
                if (selectionLog[1] == 0) {
                    action1(d, c, b, a)
                } else {
                    if (selectionLog[1] == 2) {
                        action2(d, c, b, a)
                    }
                }
            }
        }
    }
}

function action0(g, h, k, e) {
    if (status <= e++) {
        var c = cm.getNumberFromQuestInfo(500831, "roulette");
        var f = cm.getNumberFromQuestInfo(500831, "rouletteWin") + 1;
        var b = cm.getNumberFromQuestInfo(500831, "rouletteNext");
        var a = b - new Date().getTime();
        if (a <= 0) {
            cm.askYesNo("你目前获得的日冕积分为#b" + c + "分#k！\r\n如果再次转动转盘箱，赢了就可以获得#b" + f * 20 + "分#k，如果输了……就要变成#b0分#k了哦？\r\n\r\n怎么样，要挑战转盘箱吗？", 4, 9400966)
        } else {
            var d = Math.round(a / (1000 * 60));
            cm.sendOk("你目前获得的日冕积分为#b" + c + "分#k！\r\n如果想要再次转动转盘箱，还需要等待 #b" + d + "#k 分钟！", 9400966);
            cm.dispose()
        }
    } else {
        if (status === e++) {
            cm.openUIWithOption(122, 4001899)
        } else {
            if (status === e++) {
                cm.closeUI(122);
                cm.addNumberForQuestInfo(13481, "roll", 1);
                cm.addNumberForQuestInfo(13378, "RollPerDay", 1);
                cm.setNumberForQuestInfo(500831, "rouletteNext", new Date().getTime() + 30 * 60 * 1000);
                var j = cm.getNumberFromQuestInfo(13481, "rand") % 360;
                if (j >= 32 && j <= 64 || j >= 138 && j <= 234 || j >= 261 && j <= 320) {
                    cm.setNumberForQuestInfo(500831, "roulette", 0);
                    cm.setNumberForQuestInfo(500831, "rouletteWin", 0);
                    cm.sendNormalTalk("出现了#b白#k呢，虽然很可惜，但是这是我的胜利！\r\n你今天能够获得的#b日冕积分#k还是#r0分#k！请下次继续加油吧！哈哈哈哈！", 4, 9400966, false, true)
                } else {
                    cm.addNumberForQuestInfo(500831, "rouletteWin", 1);
                    var f = cm.getNumberFromQuestInfo(500831, "rouletteWin");
                    cm.addNumberForQuestInfo(500831, "roulette", f * 20);
                    var c = cm.getNumberFromQuestInfo(500831, "roulette");
                    cm.sendNormalTalk("出现了#b黑#k呢，这一轮是你赢了！\r\n你今天能够获得的#b日冕积分#k是#r" + c + "分#k！", 4, 9400966, false, true)
                }
            } else {
                if (status === e++) {
                    var j = cm.getNumberFromQuestInfo(13481, "rand") % 360;
                    if (j >= 32 && j <= 64 || j >= 138 && j <= 234 || j >= 261 && j <= 320) {
                        cm.sendNormalTalk("今天还不能满足于此？那就在#b30分钟后#k 重新转动转盘吧！说不定下次你就能赢呢？", 4, 9400966, true, false)
                    } else {
                        cm.sendNormalTalk("是见好就收，还是再来一轮？#b30分钟后#k 可以重新转动转盘，好好考虑一下吧！", 4, 9400966, true, false)
                    }
                } else {
                    cm.dispose()
                }
            }
        }
    }
}

function action1(d, c, b, a) {
    if (status <= a++) {
        cm.sendNormalTalk("#b每30分钟才能转动一次#k转盘，如果出现#b黑#k就是你赢。", 4, 9400966, false, true)
    } else {
        if (status === a++) {
            cm.sendNormalTalk("你每次获胜的时候，能够领取的#b日冕积分#k就会增加到两倍！\r\n  #b1胜：20 日冕积分#k\r\n  #b2连胜：40 日冕积分#k\r\n  #b3连胜：80 日冕积分#k\r\n#b ……#k", 4, 9400966, true, true)
        } else {
            if (status === a++) {
                cm.sendNormalTalk("日冕积分#b每天能够领取一次#k ，如果你输了，那么#b能够领取的日冕积分将初始化为0#k，所以好好判断在何时领取积分就很重要了吧？", 4, 9400966, true, true)
            } else {
                if (status === a++) {
                    cm.sendNormalTalk("如果做好了心理准备，那就转动#b转盘#k吧！", 4, 9400966, true, false)
                } else {
                    cm.dispose()
                }
            }
        }
    }
}

function action2(d, c, b, a) {
    if (status <= a++) {
        cm.dispose()
    }
};